package com.zggk.lzz.tunnelt;

import com.alibaba.fastjson.JSON;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.mvp.BasePresenterImpl;
import com.zggk.lzz.roadt.XzBean;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class TunnelTPresenter extends BasePresenterImpl<TunnelTContract.View> implements TunnelTContract.Presenter {
    @Override
    public void getJSData() {
        OkGo.<String>post(Urls.JAVASERVER5 + "proj/anHuiTunnelController/getTunnelList")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token", ""))
                .params("selectYear", "")
                .params("orgId", "")
                .params("selectType", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (mView == null)
                            return;
                        List<TunnelJSBean> roadKJBeans = JSON.parseArray(response.body(), TunnelJSBean.class);
                        List<XzBean> xzBeanList = new ArrayList<>();
                        for (int i = 0; i < 4; i++) {
                            XzBean xzBean = new XzBean();
                            if (i == 0) {//合计道数
                                xzBean.setRoad_length(roadKJBeans.get(0).getSumTunnel());
                                xzBean.setRoad_type("HJ");
                            } else if (i == 1) {//一类
                                xzBean.setRoad_length(roadKJBeans.get(0).getOneSeat());
                                xzBean.setRoad_type("YL");
                            } else if (i == 2) {//二类
                                xzBean.setRoad_length(roadKJBeans.get(0).getTwoSeat());
                                xzBean.setRoad_type("EL");
                            } else if (i == 3) {//三类
                                xzBean.setRoad_length(roadKJBeans.get(0).getThreeSeat());
                                xzBean.setRoad_type("SL");
                            }
                            xzBeanList.add(xzBean);
                        }
                        mView.getJSDatas(xzBeanList);
                    }
                });
    }

    @Override
    public void getKJData() {
        OkGo.<String>post(Urls.JAVASERVER5 + "proj/anHuiTunnelController/getTunnelList")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token", ""))
                .params("selectYear", "")
                .params("orgId", "")
                .params("selectType", "0")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (mView == null)
                            return;
                        List<TunnelJSBean> roadKJBeans = JSON.parseArray(response.body(), TunnelJSBean.class);
                        List<XzBean> xzBeanList = new ArrayList<>();
                        for (int i = 0; i < 5; i++) {
                            XzBean xzBean = new XzBean();
                            if (i == 0) {//合计座数
                                xzBean.setRoad_length(roadKJBeans.get(0).getSumTunnel());
                                xzBean.setRoad_type("HJ");
                            } else if (i == 1) {//特长隧道
                                xzBean.setRoad_length(roadKJBeans.get(0).getOneSeat());
                                xzBean.setRoad_type("TC");
                            } else if (i == 2) {//长隧道
                                xzBean.setRoad_length(roadKJBeans.get(0).getTwoSeat());
                                xzBean.setRoad_type("CS");
                            } else if (i == 3) {//中隧道
                                xzBean.setRoad_length(roadKJBeans.get(0).getThreeSeat());
                                xzBean.setRoad_type("ZS");
                            } else if (i == 4) {//短隧道
                                xzBean.setRoad_length(roadKJBeans.get(0).getFourSeat());
                                xzBean.setRoad_type("DS");
                            }
                            xzBeanList.add(xzBean);
                        }
                        mView.getKJDatas(xzBeanList);
                    }
                });
    }
}
